package the.offer.DataStructure.Impl;

import the.offer.DataStructure.Interface.Stack;

public class LinkedListStack<E extends Comparable> implements Stack<E> {

    private LinkedList<E> list;
    private int size;

    public LinkedListStack() {
        list = new LinkedList<>();
        size = 0;
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public int getSize() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("Stack: top");
        res.append(list);
        return res.toString();
    }
}
